import socket
# 在两台电脑上分别运行这个代码
print(socket.gethostbyname('lzdown27.com'))


def check_network_environment():
    """检查网络环境差异"""
    import socket
    import urllib.request

    # 检查本机IP
    hostname = socket.gethostname()
    local_ip = socket.gethostbyname(hostname)
    print(f"主机名: {hostname}, 本地IP: {local_ip}")

    # 检查公网IP
    try:
        external_ip = urllib.request.urlopen('https://api.ipify.org').read().decode('utf8')
        print(f"公网IP: {external_ip}")
    except:
        print("无法获取公网IP")

    # 测试目标域名连通性
    test_urls = [
        "https://lzdown27.com",
        "https://www.aidytt.com"
    ]

    for url in test_urls:
        try:
            response = urllib.request.urlopen(url, timeout=10)
            print(f"{url} - 可访问")
        except Exception as e:
            print(f"{url} - 不可访问: {e}")


check_network_environment()